<div id="caption">Product list</div>
<table border="0" align="center">
  <tbody>
    <?php $count = 0;?>
    <?php foreach ($products as $product): ?>
    <?php 
      $pictures = $product->Pictures;
      $expire = strtotime($product->getExpireAt());
    ?>
    <?php if ($count % 4 == 0):?>
    <tr>
    <?php endif; ?>
      <td class="product_cell">
        <div>
          <form action="<?php echo url_for("make_bid", array("pid" => $product->getId())) ?>" method="post">
            <div class="preview_picture">
              <?php foreach ($pictures as $picture): ?>
              <img src="<?php echo '/uploads/products/'.$picture->getFileName()?>" height="150" width="150" alt="<?php echo $product->getName()?>" />
              <?php endforeach; ?>
            </div>
            <div class="product_name">
              <?php echo $product->getName();?><br />
            </div>
            <div class="product_auction_price">
              Price: $<?php echo $product->getCurrentPrice();?>
            </div>
            <div class="product_bid_button">
              <button type="submit" class="bid_button" onclick="return confirm('Are you sure you want to bid for this product?');"></button>
            </div>
            <div class="product_last_bidder">
              Last bidder: <?php echo $product->getLastBidder(); ?>
            </div>
            <div class="product_time_remain">
              Time left: <div class ="timer" id="product<?php echo $count?>"></div>
            </div>
            <script type="text/javascript" language="javascript">
              $(document).ready(function(){
                var liftOffTime = new Date(
                  <?php echo date('Y', $expire);?>,
                  <?php echo date('m', $expire);?> - 1,
                  <?php echo date('d', $expire);?>,
                  <?php echo date('H', $expire);?>,
                  <?php echo date('i', $expire);?>,
                  <?php echo date('s', $expire);?>);
            	$('#product<?php echo $count?>').countdown({until: liftOffTime, layout: '{d<}{dn} {dl}, {d>}{hnn}{sep}{mnn}{sep}{snn}', compact: true});
              });
            </script>
          </form>
        </div>
      </td>
    <?php if ($count % 4 == 3):?>
    </tr>
    <?php endif; ?>
    <?php $count++ ?>
    <?php endforeach; ?>
  </tbody>
</table>